package com.qyhl.webtv.module_microvideo.shortvideo.classic.detail;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.microvideo.ClassicProgramBean;
import com.qyhl.webtv.module_microvideo.common.VideoUrl;

public class ClassicDetailModel implements ClassicDetailContract.ClassicDetailModel {
    private ClassicDetailPresenter mPresenter;

    ClassicDetailModel(ClassicDetailPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getData(String proId) {
        EasyHttp.get(VideoUrl.GET_CLASSIC_DETAIL)
                .params("proId", proId)
                .execute(new SimpleCallBack<ClassicProgramBean>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！");
                        } else {
                            mPresenter.setError("请求出错，请重新获取！");
                        }
                    }

                    @Override
                    public void onSuccess(ClassicProgramBean classicProgramBean) {
                        mPresenter.setData(classicProgramBean);
                    }
                });
    }

    @Override
    public void doComment(String name, String phone, String question, String proId) {
        EasyHttp.post(VideoUrl.POST_CLASSIC_QUESTION)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("name", name)
                .params("phone", phone)
                .params("question", question)
                .params("proId", proId)
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.commentError("提问失败，请稍后再试！");
                    }

                    @Override
                    public void onSuccess(String str) {
                        mPresenter.commentSuccess("提问成功，请等待回复！");
                    }
                });
    }

    @Override
    public void doFollow(String proId) {
        EasyHttp.get(VideoUrl.POST_CLASSIC_PROGRAM_FOLLOW)
                .params("proId", proId)
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.followResult("点赞失败！");
                    }

                    @Override
                    public void onSuccess(String str) {
                        mPresenter.followResult("点赞成功！");
                    }
                });
    }
}
